package org.tom.order.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.tom.basic.exception.MyException;
import org.tom.basic.util.JsonResult;
import org.tom.order.dto.SaveOrderDto;
import org.tom.order.service.IOrderPetService;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderPetService orderPetService;

    @PostMapping("/commitPetOrder")
    public JsonResult commitPetOrder (@RequestBody SaveOrderDto saveOrderDto){
        try {
            String sn = orderPetService.commitPetOrder(saveOrderDto);
            return JsonResult.me().setResultObj(sn);
        }catch (MyException e){
            e.printStackTrace();
            return JsonResult.me().setMsg(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("后端系统异常");
        }
    }
}
